<template>
  <div class="list_container flex both-100">
    <Breadcrumb :title="pageTitle" />
    <div class="content_container">
      <!-- 搜索模块 -->
      <el-form ref="searchMap" :inline="true" :model="searchMap" class="serach_wrapper flex-space-between">
        <div class="search">
          <el-form-item prop="safeDeviceTypeName">
            <el-input v-model="searchMap.safeDeviceTypeName" placeholder="安消设施类型名称" size="small"></el-input>
          </el-form-item>

          <el-form-item class="flex">
            <el-button @click="handleSearch()" class="btn_primary">查询</el-button>
            <el-button @click="handleReset()" class="btn_cancel">重置</el-button>
          </el-form-item>
        </div>
        <div class="edit">
          <el-form-item class="flex">
            <el-button @click="handleAdd" class="btn_primary" icon="el-icon-plus"> 新增 </el-button>
            <el-button @click="handleDelete" class="btn_primary" icon="el-icon-delete"> 删除 </el-button>
          </el-form-item>
        </div>
      </el-form>
      <!-- 搜索模块over -->

      <!-- 表格模块 -->
      <div class="table_container">
        <el-table ref="table" :data="dataList" v-loading="loading" stripe class="per_table" @selection-change="handleSelectionChange" :height="winTableH" style="width: 100%" row-key="safeDeviceTypeId">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="安消设备类型名称" align="center" prop="safeDeviceTypeName" :show-overflow-tooltip="true" />
          <el-table-column label="安消设备类型字符串" align="center" prop="safeDeviceTypeKey" :show-overflow-tooltip="true" />
          <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true"> </el-table-column>
          <el-table-column label="操作" width="150" fixed="right">
            <template slot-scope="scope">
              <div class="button-group">
                <span type="text" class="tag_primary" size="small" @click="handleEdit(scope.row)">编辑</span>
                <!-- <span type="text" class="tag_warning" size="small" @click="handleDelete(scope.row)">删除</span> -->
                <span type="text" class="tag_primary" size="small" @click="handleDetail(scope.row)">详情</span>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 表格模块over -->

      <!-- 分页 -->
      <Pagination v-show="total > 0" :total="total" :page.sync="searchMap.pageNum" :limit.sync="searchMap.pageSize" @change="getList"></Pagination>
      <!-- 分页over -->
    </div>

    <!-- 弹窗 新增/编辑 -->
    <fireSafetyEquipmentTypeForm :formData="formData" :dictMap="dict" :titleIndex="titleIndex" :dialogVisible="dialogVisible" @cancel="cancel" @getList="getList"></fireSafetyEquipmentTypeForm>
    <!-- 弹窗 新增/编辑 over -->

    <!-- 弹窗 详情 -->
    <fireSafetyEquipmentTypeDetail :descData="descData" :dictMap="dict" :dialogVisible="dialogVisibleDetail" @cancel="cancelDetail"></fireSafetyEquipmentTypeDetail>
    <!-- 弹窗 详情 over -->
  </div>
</template>

<script>
import { listSafeDeviceType, getSafeDeviceType, addSafeDeviceType, updateSafeDeviceType, delSafeDeviceType } from '@/api/fireSafetyEquipment/fireSafetyEquipmentType';
import fireSafetyEquipmentTypeForm from '@/views/system/device/fireSafetyEquipmentType/fireSafetyEquipmentTypeForm';
import fireSafetyEquipmentTypeDetail from '@/views/system/device/fireSafetyEquipmentType/fireSafetyEquipmentTypeDetail';

export default {
  name: 'fireSafetyEquipmentType',
  dicts: ['device_status', 'device_enable_status'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 搜索条件
      searchMap: {
        pageNum: 1,
        pageSize: 10,
        // safeDeviceTypeKey: '',
        safeDeviceTypeName: '',
        safeDeviceTypeId: ''
      },
      // 数据列表
      dataList: [],
      // 总条数
      total: 0,
      // 表单字段数据
      formData: {
        safeDeviceTypeId: '',
        safeDeviceTypeKey: '',
        safeDeviceTypeName: '',
        remark: ''
      },
      descData: {},
      // 弹窗-新增，编辑头文字
      titleIndex: 0,
      // 弹窗-新增/编辑-显示隐藏
      dialogVisible: false,
      // 弹窗-详情-显示隐藏
      dialogVisibleDetail: false,
    };
  },
  created() {
    this.getList();
  },
  components: {
    fireSafetyEquipmentTypeForm,
    fireSafetyEquipmentTypeDetail,
  },
  computed: {
    pageTitle() {
      return '安消设施类型';
    },
  },
  methods: {
    getList() {
      this.loading = true;
      listSafeDeviceType(this.searchMap).then(res => {
        if (200 === res.code) {
          this.dataList = res.rows
          this.total = res.rows.length;
        }
        this.loading = false;
      });
    },
    /** 查询按钮操作 */
    handleSearch() {
      this.getList();
    },
    /** 重置按钮操作 */
    handleReset() {
      this.resetForm('searchMap');
      this.searchMap.pid = 0
      this.getList()
    },
    /** 多选框选中数据 */
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.safeDeviceTypeId);
      this.multiple = !selection.length;
    },
    // 新增
    handleAdd() {
      this.titleIndex = 0;
      this.dialogVisible = true;
      this.reset();
    },
    // 修改数据
    handleEdit(row) {
      // 请求详情数据后赋值
      // getSafeDeviceType(row.safeDeviceTypeId).then(res => {
      //   if (200 === res.code) {
      this.formData = row
      this.titleIndex = 1;
      this.dialogVisible = true;
      //   }
      // })
    },
    // 删除数据
    handleDelete(row) {
      const ids = row.safeDeviceTypeId ? [row.safeDeviceTypeId] : this.ids;
      if (ids && ids.length) {
        this.$confirm('是否确认删除所选数据项？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          delSafeDeviceType(ids).then(res => {
            if (res.code == 200) {
              this.$message.success('删除成功');
              this.getList();
            }
          });
        });
      } else {
        this.$message.warning('请选择数据进行删除');
      }
    },
    // 查看详情
    handleDetail(row) {

      // 请求详情数据后赋值
      // getSafeDeviceType(row.safeDeviceTypeId).then(res => {
      //   if (200 === res.code) {
      this.descData = row;
      this.dialogVisibleDetail = true;
      //   }
      // })
    },
    // 弹窗新增编辑-取消
    cancel() {
      this.dialogVisible = false;
    },
    // 弹窗详情-取消
    cancelDetail() {
      this.dialogVisibleDetail = false;
    },
    // 表单重置
    reset() {
      this.formData = {
        safeDeviceTypeId: '',
        safeDeviceTypeKey: '',
        safeDeviceTypeName: '',
        remark: ''
      }
    },
  },
};
</script>

<style lang="less" scoped></style>
